package simple.demo;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser;

public class Main {

	static Options makeOptions() {
		Options options = new Options();
		options.addOption("T", true, "Client or Server");
		return options;
	}
	
	static void usage(Options options) {
		HelpFormatter formatter = new HelpFormatter();
		formatter.printHelp("java -cp <classpath> " + Main.class.getName(), options);
	}
	
	public static void main(String [] args) throws Exception {
		Options options = makeOptions();
		
		CommandLineParser parser = new PosixParser();
		CommandLine cmd = parser.parse(options, args);
		
		if(! cmd.hasOption("T")) {
			System.out.println("Missing type ");
			usage(options);
			System.exit(1);
		}
		
		String type = cmd.getOptionValue("T");
		if(type.equalsIgnoreCase("client"))
			new Client().run(args);
		else
			new Server().run(args);
	}

}
